<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用房屋租赁系统</title>
</head>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<body>
<form id="form1" onsubmit="return false" action="##" >
    账号<input type="text" name="name" id="name"/><br>
    密码<input type="text" name="password" id="password"/><br>
    <input type="button" value="提交" onclick="register()">
</form>
</body>

<script>
    function register() {
        $.ajax({
            url: 'register',
            method: 'POST',
            dataType: 'json',
            data: $('#form1').serialize(),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.status == 200) {
                    alert(result.data);
                    if(result.data=="注册成功"){
                        window.location.href = 'main.html';
                    }
                }
            },
            error: function () {
                alert("异常！");
            }
        })
    }
</script>
</html>